home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Development Platforms / Apple II / Apple II Sample Code / APW.SC / SC17Darts / Darts.asm / UEvent.asm < prev    next >
Encoding:
Assembly Source File  |  1990-06-24  |  12.8 KB  |  476 lines  |  [TEXT/pdos]

  1. ***********************************************************************
  2. *
  3. * darts uevent.asm -- Version 3.0 
  4. *
  5. * Copyright (c)
  6. * Steven E. Glass and Apple Computer, Inc.  1986-1990
  7. * All Rights Reserved.
  8. *
  9. * Developer Technical Support Apple II Sample Code
  10. *
  11. * This file contains the code which implements the 
  12. * main event loop used by the program.
  13. *
  14. ***********************************************************************
  15.  
  16.                case on
  17.  
  18.                copy 2/ainclude/e16.types
  19.                copy 2/ainclude/e16.event
  20.                copy 2/ainclude/e16.window
  21.                copy darts.equ
  22.  
  23.                mcopy macros/uevent.macros
  24.  
  25.                longi on
  26.                longa on
  27.  
  28. ***********************************************************************
  29. *
  30. * doScore
  31. *
  32. * This procedure does all the scoring in this program.  It is only
  33. * called when the user presses a button that has a non-zero low word
  34. * for an ID.
  35. *
  36. * How the scoring works depends on the game being played.  There is a
  37. * section for scoring each of the games.
  38. *
  39. doScore        start
  40.  
  41.                DefineStack
  42.  
  43. otherPlayer    word
  44. playerHits     word
  45. otherHits      word
  46.  
  47. saveDPage      word
  48. returnAddr     word
  49.  
  50. amount         word
  51. playerNum      word
  52.  
  53. ******************
  54.  
  55.                phd                      ;Save directPage register.
  56.                pha                      ;Make space for locals.
  57.                pha
  58.                pha
  59.                tsc                      ;Set directPage register.
  60.                tcd
  61.  
  62.                lda gameType             ;Which game?
  63.                bne crickett
  64.  
  65.                lda playerNum            ;Simple add to score for Robin.
  66.                asl a
  67.                tay
  68.                lda score,y
  69.                adc amount
  70.                sta score,y
  71.  
  72.                pei playerNum            ;Add it the the list.
  73.                pei amount
  74.                jsr addToList
  75.                pei playerNum
  76.                jsr invalScore           ;Update the score.
  77.                brl exit
  78.  
  79. crickett       lda playerNum
  80.                eor #1
  81.                sta otherPlayer
  82.  
  83.                pei playerNum            ;How many hits for this player.
  84.                pei amount
  85.                jsr getCTval
  86.                sta playerHits
  87.                pei otherPlayer          ;And how many for other.
  88.                pei amount
  89.                jsr getCTval
  90.                sta otherHits
  91.  
  92.                cmp #3                   ;See if either is still open.
  93.                bcc atLeastOneOpen
  94.                lda playerHits
  95.                cmp #3
  96.                bcs neitherOpen
  97.  
  98. atLeastOneOpen pei playerNum            ;Increment player hit value.
  99.                pei amount
  100.                jsr getCTval
  101.                inc a
  102.                sta playerHits
  103.                sta crickettTables,y
  104.  
  105.                pei playerNum            ;Change the hit indicator for button.
  106.                pei amount
  107.                jsr fixButtonTitle
  108.  
  109.                lda playerHits           ;See if we can count this one.
  110.                cmp #3+1
  111.                bcc noCount
  112.                lda otherHits
  113.                cmp #3
  114.                bcs noCount
  115.  
  116.                lda playerNum            ;It counts -- add it in.
  117.                asl a
  118.                tay
  119.                lda score,y
  120.                adc amount
  121.                sta score,y
  122.                pei playerNum
  123.                jsr invalScore
  124.  
  125. noCount        pei playerNum            ;Add it to list -- score or no score.
  126.                pei amount
  127.                jsr addToList
  128.  
  129. neitherOpen    lda weHaveAWinner        ;Make sure we don't already have winner.
  130.                bne alreadyHaveWinner
  131.  
  132.                ldx #15                  ;Scan the relavent button to see that
  133. aa             pei playerNum            ;this player has them all closed.
  134.                phx
  135.                jsr getCTval
  136.                cmp #3
  137.                bcc aaz                  ;Here is an open one -- carry clear.
  138.                inx
  139.                cpx #21
  140.                bcc aa
  141.                php
  142.                ldx #25
  143.                plp
  144.                beq aa                   ;Fall out if all closed -- carry set.
  145. aaz            bcc stillOneOpen
  146.                lda playerNum
  147.                asl a
  148.                tay
  149.                lda otherPlayer
  150.                asl a
  151.                tax
  152.                lda score,y              ;player's score
  153.                cmp score,x              ;other player's score
  154.                bcc noWinnerYet          ;Only if are all closed, and this
  155. *                                       ;player is ahead.
  156.  
  157.                inc weHaveAWinner        ;Bingo.
  158.  
  159.                PushLong theWindow
  160.                _BeginUpdate
  161.                jsl drawThisWindow
  162.                PushLong theWindow
  163.                _EndUpdate
  164.  
  165.                pea refIsResource*2
  166.                PushLong #0
  167.                PushLong #3
  168.                _AlertWindow
  169.  
  170. alreadyHaveWinner anop
  171. stillOneOpen   anop
  172. noWinnerYet    anop
  173. exit           anop
  174.                pla                      ;Remove local variable space.
  175.                pla
  176.                pla
  177.                pld                      ;Restore directPage register.
  178.                plx                      ;Save return address.
  179.                pla                      ;Remove passed parameters.
  180.                pla
  181.                phx                      ;Restore return address and return.
  182.                rts
  183.  
  184.                end
  185.  
  186.  
  187.  
  188.  
  189. * INPUTS:         playerNum & amount -- on stack.
  190. * OUTPUTS:        YREG:    index into crickettTables
  191. *                 ACC:     value at crickettTables[index]
  192. *                 XREG:    preserved.
  193. *
  194. getCTval       start
  195.  
  196.                lda 5,s                  ;playerNum (0 or 1)
  197.                asl a                    ;*2
  198.                adc 5,s                  ;*3
  199.                asl a                    ;*6
  200.                asl a                    ;*12
  201.                adc 5,s                  ;*13
  202.                asl a                    ;*26
  203.                asl a                    ;*52
  204.                adc 3,s                  ;amount
  205.                adc 3,s                  ;elements are words
  206.                sta 5,s                  ;index
  207.  
  208.                pla                      ;return address
  209.                ply                      ;amount
  210.                ply                      ;index
  211.                pha
  212.                lda crickettTables,y     ;crickettTables value
  213.                rts
  214.  
  215.                end
  216.  
  217. ***********************************************************************
  218. *
  219. * doControls
  220. *
  221. * This procedure is called by mainEvent whenever taskmaster
  222. * returns inControl.
  223. *
  224. doControls     start
  225.  
  226.                DefineStack
  227.  
  228. whichButton    word
  229. buttonNum      word
  230. lastItem       word
  231. playerNum      word
  232.  
  233. saveDPage      word
  234. returnAddr     word
  235.  
  236. ******************
  237.  
  238.                phd                      ;Save directPage register.
  239.                pha                      ;Make space for locals.
  240.                pha
  241.                pha
  242.                pha
  243.                tsc                      ;Set directPage register.
  244.                tcd
  245.  
  246.                ldx #Player1             ;Assume Player1
  247.  
  248.                lda event+owmTaskData4
  249.                beq loWordZero
  250.  
  251.                bpl aa
  252.                ldx #Player2             ;Assumption wrong.
  253.  
  254. aa             stx playerNum
  255.                and #$7FFF
  256.                sta whichButton
  257.  
  258.                pei playerNum
  259.                pha                      ;whichButton
  260.                jsr doScore
  261.                bra exit
  262.  
  263. loWordZero     lda event+owmTaskData4+2
  264.                cmp #1
  265.                bcc noCase
  266.                bne notCase1
  267.  
  268. case1          pha                      ;Result space.
  269.                pea refIsResource*2
  270.                PushLong #0
  271.                PushLong #ConfirmTextID
  272.                _AlertWindow
  273.                pla
  274.                cmp #1
  275.                bne exit
  276.                jsr doQuitItem
  277.                bra exit
  278.  
  279. case2          jsr doNewItem            ;Inits current window for new game.
  280.                bra exit
  281.  
  282. notCase1       ldx #Player1
  283.                cmp #3
  284.                bcc case2
  285.                beq case3
  286.  
  287. case4          ldx #Player2
  288. case3          lda event+owmClickCount
  289.                cmp #2
  290.                bcc exit
  291.                stz event+owmClickCount
  292.                phx                      ;Which player
  293.                jsr removeSelected       ;Delete selected items from list.
  294.  
  295. noCase         anop
  296. exit           pla                      ;Remove local variable space.
  297.                pla
  298.                pla
  299.                pla
  300.                pld                      ;Restore directPage register.
  301.                rts
  302.  
  303.                end
  304.  
  305.  
  306.  
  307. disableItems   start
  308.                pea NewItem
  309.                _DisableMItem
  310.                pea QuitItem
  311.                _DisableMItem
  312.                pea AboutItem
  313.                _DisableMItem
  314.                rts
  315.  
  316.                end
  317.  
  318.  
  319. enableItems    start
  320.                pea NewItem
  321.                _EnableMItem
  322.                pea QuitItem
  323.                _EnableMItem
  324.                pea AboutItem
  325.                _EnableMItem
  326.                rts
  327.  
  328.                end
  329.  
  330. ***********************************************************************
  331. *
  332. * checkFrontW
  333. *
  334. * This routine adjusts the system menu bar depending on what window is
  335. * selected.  It activates the edit menu if a desk accessory is opened
  336. * and selected.  It deactivates the edit menu if the game window
  337. * becomes active again.
  338. *
  339. * We do this because it makes no sense to have progam menus active when
  340. * a desk accessory is active and there is no sense having the edit menu
  341. * active when this program does not use it.
  342. *
  343. * It is called every time through the event loop.  The global variable
  344. * lastWindow helps us from making lots of checks if nothing has changed.
  345. *
  346. checkFrontW    start
  347.  
  348. ******************
  349.  
  350.                pha                      ;Get top window.
  351.                pha
  352.                _FrontWindow
  353.                pla
  354.                plx
  355.  
  356.                cmp lastWindow           ;Is it the same as last time?
  357.                bne notSameWind
  358.                cpx lastWindow+2
  359.                bne notSameWind
  360.                brl sameWind             ;Yes, do nothing.
  361.  
  362. notSameWind    sta lastWindow           ;New 'last' window.
  363.                stx lastWindow+2
  364.  
  365.                ora lastWindow+2
  366.                bne thereIsOne           ;Make sure that we have one.
  367.  
  368. noWindow       pea $80                  ;We don't.
  369.                pea EditMenuID
  370.                _SetMenuFlag
  371.                _DrawMenuBar
  372.                jsr disableItems
  373.                bra exit
  374.  
  375. thereIsOne     pha                      ;Check for DA's.
  376.                PushLong lastWindow
  377.                _GetSysWFlag
  378.                pla
  379.                beq notSysWind
  380.  
  381.                jsr disableItems         ;Make menus correct for DA's.
  382.                pea $FF7F
  383.                pea EditMenuID
  384.                _SetMenuFlag
  385.                pea $80
  386.                pea GameMenuID
  387.                _SetMenuFlag
  388.                _DrawMenuBar
  389.                jmp exit
  390.  
  391. notSysWind     pea $80                  ;Make menus correct for us.
  392.                pea EditMenuID
  393.                _SetMenuFlag
  394.                pea $FF7F
  395.                pea GameMenuID
  396.                _SetMenuFlag
  397.                _DrawMenuBar
  398.                jsr enableItems
  399.  
  400. sameWind       anop
  401. exit           anop
  402.                rts
  403.  
  404.                end
  405.  
  406. ***********************************************************************
  407. *
  408. * mainEvent
  409. *
  410. * This is the main routine in the program.  It continuously calls
  411. * taskmaster and handles any events that occur.  It also keeps the
  412. * right menus active by calling checkFrontW.
  413. *
  414. mainEvent      start
  415.  
  416.                DefineStack
  417.  
  418. code           word
  419. checkFirstUpdate word
  420.  
  421. saveDPage      word
  422. returnAddr     word
  423.  
  424. ******************
  425.  
  426.                phd                      ;Save directPage register.
  427.                pha                      ;Make space for locals.
  428.                pha
  429.                tsc                      ;Set directPage register.
  430.                tcd
  431.  
  432.                stz quitFlag
  433.                lda #1
  434.                sta checkFirstUpdate
  435.                stz lastWindow
  436.                stz lastWindow+2
  437.  
  438. loopLongAndHard jsr checkFrontW         ;Loop almost forever.
  439.                pha
  440.                pea $FFFF
  441.                PushLong #event
  442.                _TaskMaster
  443.                pla
  444.  
  445.                cmp #wInSpecial
  446.                beq menuCase
  447.                cmp #wInMenuBar
  448.                bne aa
  449.  
  450. menuCase       jsr doMenu
  451.                bra next
  452.  
  453. aa             cmp #wInControl
  454.                bne default
  455.                jsr doControls
  456.                bra next
  457.  
  458. default        lda checkFirstUpdate
  459.                beq next
  460.                lda firstUpdateComplete
  461.                beq next
  462.                _InitCursor
  463.                stz checkFirstUpdate
  464.  
  465. next           lda quitFlag
  466.                beq loopLongAndHard
  467.  
  468.                pla                      ;Remove local variable space.
  469.                pla
  470.                pld                      ;Restore directPage register.
  471.                rts
  472.  
  473.                end
  474.  
  475.                END
  476.